package com.hxq.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hxq.domain.entity.User1;
import com.hxq.mapper.User1Mapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Service
@RequiredArgsConstructor
public class User1Service extends ServiceImpl<User1Mapper, User1> {

    @Transactional(propagation = Propagation.REQUIRED)
    public void addRequired(User1 user1){
        baseMapper.insert(user1);
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void addRequiresNew(User1 user){
        baseMapper.insert(user);
    }

    @Transactional(propagation = Propagation.NESTED)
    public void addNested(User1 user){
        baseMapper.insert(user);
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    public void addSupports(User1 user){
        baseMapper.insert(user);
    }

    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public void addNotSupported(User1 user){
        baseMapper.insert(user);
    }

    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public void addNotSupportedException(User1 user){
        baseMapper.insert(user);
        throw new RuntimeException();
    }

    @Transactional(propagation = Propagation.NOT_SUPPORTED,readOnly=true)
    public User1 getNotSupported(Integer id){
        return baseMapper.selectById(id);
    }
}
